package com.fjw.mapper;

import com.fjw.pojo.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 文章管理Mapper接口
 * 提供Article表的数据库操作方法
 */
@Mapper
public interface ArticleMapper {
    /**
     * 新增文章
     */
    @Insert("insert into Article(title,content,job_category,major_category,author) values (#{title},#{content},#{job_category},#{major_category},#{author})")
    void add(Article article);

    /**
     * 通过ID查找文章
     */
    @Select("select * from Article where id=#{id}")
    Article findById(Integer id);
    /**
     * 通过职业分类和专业分类查找文章
     */
    @Select("select * from Article where job_category=#{job_category} and major_category=#{major_category}")
    List<Article> findByCategory(String job_category, String major_category);
    /**
     * 通过职业分类查找文章
     */
    @Select("select * from Article where job_category=#{job_category}")
    List<Article> findByJobCategory(String job_category);

    /**
     * 通过专业分类查找文章
     */
    @Select("select * from Article where major_category=#{major_category}")
    List<Article> findByMajorCategory(String major_category);

    /**
     * 通过作者ID查找文章
     */
    @Select("select * from Article where author=#{author}")
    List<Article> findByAuthor(Integer author);

    /**
     * 通过ID删除文章
     */
    @Delete("delete from Article where id=#{id}")
    void deleteById(Integer id);

    /**
     * 通过ID更新文章信息
     */
    @Update("update Article set title=#{title},content=#{content},job_category=#{job_category},major_category=#{major_category} where id=#{id} ")
    void updateById(Article article);

    /**
     * 获取全部文章列表
     */
    @Select("select * from Article")
    List<Article> getAll();
}
